package main

import (
	"fmt"
	"time"

	"github.com/bytedance/sonic"
	"github.com/hibiken/asynq"
)

type EmailPayload struct {
	UserID int
}

func main() {
	redisConnOpt := asynq.RedisClusterClientOpt{
		Addrs: []string{
			"192.168.0.138:6379",
			"192.168.0.143:6379",
			"192.168.0.140:6379",
			"192.168.0.142:6379",
			"192.168.0.141:6379",
			"192.168.0.139:6379",
		},
	}

	client := asynq.NewClient(redisConnOpt)

	payload1, _ := sonic.Marshal(struct {
		UserID int
		Name   string
	}{UserID: 123, Name: "Jon"})

	t1 := asynq.NewTask("email:welcome", payload1)
	_, _ = client.Enqueue(t1, asynq.ProcessIn(10*time.Second), asynq.Queue("low"))

	payload2, _ := sonic.Marshal(struct {
		UserID int
		Name   string
	}{UserID: 456, Name: "Sun"})

	t2 := asynq.NewTask("email:reminder", payload2)
	_, _ = client.Enqueue(t2, asynq.Queue("low"))

	// log.Printf("%#v", taskInfo)
	// {ID:"0d7bdbdd-f238-45b6-bcff-e012af8db7d5", Queue:"low", Type:"email:welcome", Payload:[]uint8{0x7b, 0x22, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x22, 0x3a, 0x31, 0x7d}, State:3, MaxRetry:25, Retried:0, LastErr:"", LastFailedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Timeout:1800000000000, Deadline:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Group:"", NextProcessAt:time.Date(2025, time.July, 29, 10, 50, 51, 435780300, time.Local), IsOrphaned:false, Retention:0, CompletedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)

	payload3, _ := sonic.Marshal(struct {
		UserID int
		Title  string
	}{UserID: 456, Title: "618 coming"})

	t3 := asynq.NewTask("email:ad", payload3)
	client.Enqueue(t3, asynq.Queue("high"))

	fmt.Println("running...")

	time.Sleep(1 * time.Minute)

	fmt.Println("App exited")
}
